package com.deryun.tyl.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.deryun.tyl.bean.Publicity;
import com.deryun.tyl.bean.Purchasing;
import com.deryun.tyl.bean.User;
import com.deryun.tyl.dao.impl.PurchasingDaoImpl;

@Service("purchasingServiceImpl")
public class PurchasingServiceImpl {
	
	@Resource(name="purchasingDaoImpl")
	private PurchasingDaoImpl purchasingDaoImpl;
	
	public int addPurchasing(HttpServletRequest request,Purchasing purchasing){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		purchasing.setPublishDate(df.format(new Date()));
		purchasing.setPublishMan(((User)request.getSession().getAttribute("user")).getContactMan());
		purchasing.setPublishUserId(((User)request.getSession().getAttribute("user")).getId().toString());
		return purchasingDaoImpl.addPurchasing(purchasing);
	}
	
	public List<Purchasing> getAllPurchasing(){
		return purchasingDaoImpl.getAllPurchasing();
	}
	
	public List<Purchasing> getUserPurchasing(String publishUserId){
		return purchasingDaoImpl.getUserPurchasing(publishUserId);
	}
	
	public int deletePurchasing(int id){
		return purchasingDaoImpl.deletePurchasing(id);
	}
	
	public int modifyPurchasing(Purchasing purchasing){
		return purchasingDaoImpl.modifyPurchasing(purchasing);
	}
	
	public Purchasing getPurchasingById(int id){
		return purchasingDaoImpl.getPurchasingById(id);
	}
	
	public int setResult(Purchasing purchasing){
		return purchasingDaoImpl.setResult(purchasing);
	}
}
